package com.example.servlet.response;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @program: sms
 * @description:
 * @author: zhanghz001
 * @create: 2020-11-02 14:26
 **/
@WebServlet("/response9")
public class ResponseDemo9 extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //注意事项
        //字节流和字符流不用关闭可以,应用会自动帮忙关闭
        //字符流和字节流只能选择一个
        resp.setContentType("text/html;charset=utf-8");
        resp.getOutputStream().write("这是一个寂寞的天,下着有些伤心的雨".getBytes("utf-8"));
        resp.getWriter().write("看来是要出错了");
    }

}
